package woniuxy.happylife.test;


import com.woniuxy.happylife.auth.AuthApplication2021;
import com.woniuxy.happylife.auth.service.LoginService;
import com.woniuxy.happylife.entity.User;
import lombok.val;


import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.time.Duration;

/**
 * @Title: authtest
 * @ProjectName: happy-life
 * @Description: TODO
 * @Author: chowinggum
 * @Date: 2022/2/17 11:31
 */
@SpringBootTest(classes = AuthApplication2021.class)
public class authtest {
    @Resource
    RedisTemplate redisTemplate;
    @Resource
    LoginService loginService;
    @Test
    public void test1(){

        redisTemplate.opsForHash().put("token","123",123);
        redisTemplate.opsForHash().put("token","321",123);
        redisTemplate.opsForHash().put("token","111",123);

//        System.out.println(redisTemplate);
    }
    @Test
    public void test2(){
        User user = new User();
        user.setUsername("123");
        user.setMpassword("123");
//        user.setRoles("123");
        //user.setRoles("123");
        redisTemplate.opsForHash().put("token","123",user);
        redisTemplate.expire("token", Duration.ofMinutes(30));
        redisTemplate.opsForHash().put("tokencopy","123","cyg");
        redisTemplate.expire("tokencopy",Duration.ofMinutes(60));
        User token = (User)redisTemplate.opsForHash().get("token", "123");

//        System.out.println(token.getRoles());
    }
    @Test
    public void test03(){
        loginService.enroll("125","123");

      //  System.out.println(token.getRoles());
    }

}
